package com.ak.httpclient;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;


//@Slf4j
public class MyHttpGet {

    public static void main(String[] args) {
        // 打开浏览器
        CloseableHttpClient aDefault = HttpClients.createDefault();
        // 输入网址 https://movie.douban.com/chart
        HttpGet httpGet=new HttpGet("https://www.baidu.com");
        CloseableHttpResponse response=null;
        try {
            // 获取响应内容

           response= aDefault.execute(httpGet);
          // System.out.println(response);
            if(response.getStatusLine().getStatusCode()==200){
                String content = EntityUtils.toString(response.getEntity());
                System.out.println(content.length());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            // 关闭流
            if(response!=null){
                try {
                    response.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
